﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!--Defines possible lifeline types.-->
  <xs:simpleType name="lifeline_type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="normal" />
      <xs:enumeration value="actor" />
    </xs:restriction>
  </xs:simpleType>
  <!--Defines possible message types.-->
  <xs:simpleType name="message_type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="call" />
      <xs:enumeration value="return" />
      <xs:enumeration value="self" />
      <xs:enumeration value="recursive" />
      <xs:enumeration value="duration" />
      <xs:enumeration value="create" />
      <xs:enumeration value="found" />
      <xs:enumeration value="lost" />
    </xs:restriction>
  </xs:simpleType>
  <!--Defines possible constraint types.-->
  <xs:simpleType name="constraint_type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="duration" />
      <xs:enumeration value="time" />
    </xs:restriction>
  </xs:simpleType>
  <!--Defines possible combined fragment types.-->
  <xs:simpleType name="combined_fragment_type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="loop" />
      <xs:enumeration value="alt" />
    </xs:restriction>
  </xs:simpleType>
  <!--Defines an element reference type. It is used to reference diagram items.-->
  <xs:complexType name="element_reference">
    <xs:attribute name="name" type="xs:string" use="required" />
  </xs:complexType>
  <!--Defeines the base type of combined fragments. Other combined fragment types inherit from it.-->
  <xs:complexType name="combined_fragment_base">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="combined_fragment_type" use="required" />
  </xs:complexType>
  <!--Defines generic combined fragment type, which can be used for one-section combined fragments like 'loop'.-->
  <xs:complexType name="combined_fragment">
    <xs:complexContent>
      <xs:extension base="combined_fragment_base">
        <xs:sequence>
          <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="unbounded" /><!--References a message.-->
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!--Defines a type for combined fragments of 'alt' type.-->
  <xs:complexType name="combined_fragment_alt">
    <xs:complexContent>
      <xs:extension base="combined_fragment_base">
        <xs:sequence>
          <xs:element name="main" minOccurs="1" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="ref" type="element_reference" minOccurs="0" maxOccurs="unbounded" /><!--References a message.-->
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="alt" minOccurs="1" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="ref" type="element_reference" minOccurs="0" maxOccurs="unbounded" /><!--References a message.-->
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!--The root element.-->
  <xs:element name="model">
    <xs:complexType>
      <xs:sequence>
        <!--Defines a list stereotypes.-->
        <xs:element name="stereotypes" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="stereotype" minOccurs="0" maxOccurs="unbounded" >
                <xs:complexType>
                  <xs:attribute name="name" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!--Defines a list of diagrams.-->
        <xs:element name="diagrams" minOccurs="1" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <!--Defines a UML diagram.-->
              <xs:element name="sequenceDiagram" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <!--Defines a list of lifelines.-->
                    <xs:element name="lifelines" minOccurs="1" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a lifeline.-->
                          <xs:element name="lifeline" minOccurs="1" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="data_type" type="xs:string" use="optional" />
                              <xs:attribute name="type" type="lifeline_type" use="required" />
                              <xs:attribute name="stereotypes" type="xs:string" use="optional" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of messages.-->
                    <xs:element name="messages" minOccurs="1" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a message.-->
                          <xs:element name="message" minOccurs="0" maxOccurs="unbounded" >
                            <xs:complexType>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="type" type="message_type" use="required" />
                              <xs:attribute name="source" type="xs:string" use="required" /><!--References a lifeline.-->
                              <xs:attribute name="target" type="xs:string" use="required" /><!--References a lifeline or a REF.-->
                              <xs:attribute name="async" type="xs:boolean" use="optional" />
                              <xs:attribute name="label" type="xs:string" use="required" />
                              <xs:attribute name="stereotypes" type="xs:string" use="optional" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of constraints.-->
                    <xs:element name="constraints" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a constraint.-->
                          <xs:element name="constraint" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="1" /><!--References a message.-->
                              </xs:sequence>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="type" type="constraint_type" use="required" />
                              <xs:attribute name="value" type="xs:string" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of combined fragments.-->
                    <xs:element name="combined_fragments" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="combined_fragment" type="combined_fragment" minOccurs="0" maxOccurs="unbounded" />
                          <xs:element name="combined_fragment_alt" type="combined_fragment_alt" minOccurs="0" maxOccurs="unbounded" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of invariants.-->
                    <xs:element name="invariants" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines an invariant.-->
                          <xs:element name="invariant" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="value" type="xs:string" use="required" />
                              <xs:attribute name="lifeline" type="xs:string" use="required" />
                              <!--References a lifeline.-->
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of destruction elements.-->
                    <xs:element name="destructions" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a destruction element.-->
                          <xs:element name="destruction" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="message" type="xs:string" use="optional" />
                              <!--Optionally reference a message.-->
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of continuations.-->
                    <xs:element name="continuations" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a continuation.-->
                          <xs:element name="continuation" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="unbounded" /><!--References a lifeline.-->
                              </xs:sequence>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="value" type="xs:string" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of concurrents.-->
                    <xs:element name="concurrents" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines a concurrent.-->
                          <xs:element name="concurrent" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="unbounded" /><!--References a message.-->
                              </xs:sequence>
                              <xs:attribute name="name" type="xs:string" use="required" />
                              <xs:attribute name="lifeline" type="xs:string" use="required" /><!--References a lifeline.-->
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a list of interaction elements.-->
                    <xs:element name="references" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <!--Defines an interaction element.-->
                          <xs:element name="reference" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="unbounded" /><!--References a lifeline.-->
                              </xs:sequence>
                              <xs:attribute name="name" type="xs:string" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--Defines a sequence of objects in the diagram.-->
                    <xs:element name="sequence" minOccurs="1" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="ref" type="element_reference" minOccurs="1" maxOccurs="unbounded" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="name" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>